package com.lurencun.android.topicbank.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.lurencun.android.support.ui.BackUIActivity;
import com.lurencun.android.topicbank.R;
import com.lurencun.android.topicbank.presist.PracticeResult;
import com.lurencun.android.topicbank.util.DateUtil;
import com.lurencun.android.topicbank.util.TimeUtil;

public class ResultActivity extends BackUIActivity {

	private final static String SCORE_TIP = "得分：%d";
	private final static String CORRECT_TIP = "正确：%d";
	private final static String MISTAKE_TIP = "错误：%d";
	private final static String USED_TIME_TIP = "花费时间：%s";
	
	private Button mConfirmBtn;

	@Override
	protected int getBackButtonResId() {
		return R.id.back_button;
	}

	@Override
	protected int getContentViewLayoutId() {
		return R.layout.practice_result;
	}

	@Override
	protected boolean isConfirmBack() {
		return false;
	}

	@Override
	protected void onCreateEx(Bundle bundle) {
		Intent intent = this.getIntent();
		Bundle intentBundle = intent.getExtras();
		PracticeResult result = (PracticeResult) intentBundle.getSerializable("random_practice_result");
		TextView topicMetaTime = (TextView) findViewById(R.id.topic_meta_time);
		TextView topicMetaScore = (TextView) findViewById(R.id.topic_meta_score);
		TextView topicMetaCorrect = (TextView) findViewById(R.id.topic_meta_correct);
		TextView topicMetaMistake = (TextView) findViewById(R.id.topic_meta_mistake);
		TextView topicMetaUsedTime = (TextView) findViewById(R.id.topic_meta_used_time);
		
		if(result!=null) {
			topicMetaTime.setText(DateUtil.getStringFromDate(result.getStartTime()));
			topicMetaScore.setText(String.format(SCORE_TIP, result.getScore()));
			topicMetaCorrect.setText(String.format(CORRECT_TIP, result.getCorrectCount()));
			topicMetaMistake.setText(String.format(MISTAKE_TIP, result.getFailureCount()));
			topicMetaUsedTime.setText(String.format(USED_TIME_TIP, TimeUtil.parseTime(result.getTimeUsed())));
		}
		else {
			
		}
		mConfirmBtn = (Button) findViewById(R.id.confirmBtn);
		mConfirmBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}

}
